﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;

public partial class Web_StockReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["current"] = "Stock Report";//current page
        if (Session["user"] != null)//check user
        {
            string user = Session["user"].ToString();
            if (user == "viewer")
            {
                Response.Redirect("index.aspx");
            }

        }
        else
        {
            Response.Redirect("index.aspx");
        }
        if (IsPostBack == true)//generate report
        {
            button();
            button();
        }
    }

    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        try
        {
            button();
        }
        catch
        {
            Response.Redirect("404.ASPX");
        }
        }

    public Boolean button()
    {
        try
        {
            ReportDocument reportdocument = new ReportDocument();
            reportdocument.Load(Server.MapPath("Bin/StockReport.rpt"));
            reportdocument.SetDatabaseLogon("sa", "MahinBL2012@");
            reportdocument.SetParameterValue("From", ASPxDateEdit1.Text);
            reportdocument.SetParameterValue("To", ASPxDateEdit2.Text);
            CrystalReportViewer1.ReportSource = reportdocument;
            return true;
        }
        catch
        {
            Response.Redirect("404.ASPX");
            return false;
        }
    }
}